package com.bst.base.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import org.springframework.stereotype.Controller;
import com.bst.common.enums.BusinessType;
import com.bst.base.domain.BaseReportCache;
import com.bst.base.service.IBaseReportCacheService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 报表数据缓存Controller
 * 
 * @author laoliu
 * @date 2024-11-06
 */
@Controller
@RequestMapping("/base/report/cache")
public class BaseReportCacheController extends BaseController
{
    private String prefix = "base/cache";

    @Autowired
    private IBaseReportCacheService baseReportCacheService;

    @GetMapping()
    public String cache()
    {
        return prefix + "/cache";
    }

    /**
     * 查询报表数据缓存列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseReportCache baseReportCache)
    {
        startPage();
        List<BaseReportCache> list = baseReportCacheService.selectBaseReportCacheList(baseReportCache);
        return getDataTable(list);
    }

    /**
     * 导出报表数据缓存列表
     */
    @Log(title = "报表数据缓存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseReportCache baseReportCache)
    {
        List<BaseReportCache> list = baseReportCacheService.selectBaseReportCacheList(baseReportCache);
        ExcelUtil<BaseReportCache> util = new ExcelUtil<BaseReportCache>(BaseReportCache.class);
        return util.exportExcel(list, "报表数据缓存数据");
    }

    /**
     * 新增报表数据缓存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报表数据缓存
     */
    @Log(title = "报表数据缓存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseReportCache baseReportCache)
    {
        return toAjax(baseReportCacheService.insertBaseReportCache(baseReportCache));
    }

    /**
     * 修改报表数据缓存
     */
    @GetMapping("/edit/{idReportCache}")
    public String edit(@PathVariable("idReportCache") Long idReportCache, ModelMap mmap)
    {
        BaseReportCache baseReportCache = baseReportCacheService.selectBaseReportCacheByIdReportCache(idReportCache);
        mmap.put("baseReportCache", baseReportCache);
        return prefix + "/edit";
    }

    /**
     * 修改保存报表数据缓存
     */
    @Log(title = "报表数据缓存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseReportCache baseReportCache)
    {
        return toAjax(baseReportCacheService.updateBaseReportCache(baseReportCache));
    }

    /**
     * 删除报表数据缓存
     */
    @Log(title = "报表数据缓存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseReportCacheService.deleteBaseReportCacheByIdReportCaches(ids));
    }
}
